<#assign ctx = request.contextPath />
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
		<meta name="description" content="${company.introduceContent2?if_exists}" />
		<title>${company.introduceTitle2?if_exists}</title>
		<link rel="stylesheet" href="${ctx}/assets/css/bootstrap.css" />
		<link rel="stylesheet" href="${ctx}/assets/css/sco.message.css" />
		<link rel="stylesheet" href="${ctx}/assets/css/shareqrcode.css" />
		<style>
			
		</style>
	</head>
	
	<body>
	
		<div id="weixin_download" style="width:100%;height:100vh;background-image:url('${ctx}/assets/img/xiazai_bg.png');background-repeat: no-repeat;background-size: 100% 100%;text-align:center;color:#fff">
			<#if wxsetting.wxQrCode?? && (wxsetting.wxQrCode?length>0)>
			<div id="qrcode" style="position:absolute;left:25%;top:30px;width:50%;">
				<img src="${ctx}/${wxsetting.wxQrCode?if_exists}" width="100%" height="100%">
				<h4><b>扫描关注公众号</b></h4>
			</div>
			</#if>
			
			<div id="ios_down_div" style="z-index:900;width:46%;height:50px;position:absolute;left:27%;bottom:90px">
				<img src="${ctx}/assets/img/xiazai_ios_bg.png" width="100%" height="100%">
			</div>
			
			<div id="and_down_div" style="z-index:900;width:46%;height:50px;position:absolute;left:27%;bottom:20px">
				<img src="${ctx}/assets/img/xiazai_and_bg.png" width="100%" height="100%">
			</div>

		</div>
		
		<div id="weixin_qq">
			<img src="${ctx}/assets/img/weixinxiazai.png" width="100%" height="100%" style="z-index:999;position:absolute;left:0;top:0">
		</div>
	
		
		<div id="getApp">
			<#if company.picture2?? && (company.picture2?length>0)>
				<img id="bg_img" src="${ctx}/${company.picture2?if_exists}" width="100%" height="100%" style="z-index:-100;position:absolute;left:0;top:0">
			<#else>
				
			</#if>
	
		  	<div class="top"></div>
		  	<div class="nav">
		  		<form id="submit_form"  action="" method="post">
					<input type="hidden" id="id" name="id" value="${driver.id}"/>
					<div class="input-group">
					  <input id="phone" name="phone" type="number" class="form-control input-lg" placeholder="请填写您的手机号码" aria-describedby="basic-addon2">
					  <span class="input-group-addon" id="getCode" disable="false">获取验证码</span>
					</div>
					<div class="input-group">
					  <input id="code" name="code" type="number" class="form-control input-lg" placeholder="请填写验证码" aria-describedby="basic-addon2">
					  <span class="input-group-addon" id="submit_button">确认</span>
					</div>
				</form>
			</div>
		</div>	
	  </body>
	  <script src="${ctx}/assets/js/jquery-1.11.0.min.js" type="text/javascript"></script>
	  <script src="${ctx}/assets/js/bootstrap.min.js" type="text/javascript"></script>
	  <script src="${ctx}/assets/js/sco.message.js" type="text/javascript"></script>
	  <script>
	  	$(document).ready(function(){
	  	
	  			$("#qrcode").height($("#qrcode").width() + "px")

	  			// 隐藏所有
	  			$("#weixin_download").hide()
	  			$("#ios_down_div").hide();
	  			$("#and_down_div").hide();
	  			$("#weixin_qq").hide();
	  			$("#getApp").hide();
	  			
	  			// 判断显示
	  			if (is_weixin()) {
	  				$("#weixin_qq").show()
	  			} else {
	  				$("#getApp").show();
	  			}
	  	
				//表单提交
				$("#submit_button").click(function(){
					
					var phone = $("#phone").val();
					var isphone=/^[0-9]{1,15}$/; 
					if (!isphone.test(phone)){
						$.scojs_message("请填写正确的手机号码！", $.scojs_message.TYPE_ERROR);
						return;
					}
					
					var code = $("#code").val();
					if (code == "" || code.length != 4){
						$.scojs_message("请填写正确的验证码！", $.scojs_message.TYPE_ERROR);
						return;
					}
					
					
					var params = {phone:phone,code:code,id:$("#id").val()}
					
					$("#submit_button").attr("disabled",true);
					$.post('${ctx}/driver/api/rest/v3/downloadShareQrCode',params,function(data){
						if(data.success){
							$("#phone").val("");
							$("#code").val("");
							zdxz(data.map.androidUrl,data.map.iosUrl);
						}
						else{
							$("#submit_button").attr("disabled",false);
							$.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
						}
					});
				
				});
				
				$("#getCode").click(function(){
					if($("#getCode").attr("disable")=="false"){
						var phone = $("#phone").val();
						if (phone == "" || phone.length != 11){
							$.scojs_message("请填写正确的手机号码！", $.scojs_message.TYPE_ERROR);
							return;
						}
					
					
						$("#getCode").attr("disable",true);
						$.get('${ctx}/driver/api/rest/v3/smsQrCode',{'phone':phone,'driverIntroducerId':$("#id").val()},function(result){
							if(result.success){
								$.scojs_message("验证码已发送成功", $.scojs_message.TYPE_OK);
								smsOverTime(120);
							}
							else{
								if(result.errorcode=="0"){
									smsOverTime(result.object);
								}
								else if(result.errorcode=="1"){
									$.scojs_message("短信发送失败，请稍后再试", $.scojs_message.TYPE_ERROR);
									$("#getCode").attr("disable",false);
								}
							}
						});
					}
				});
				
				
				var height=$(document).height();
				$("#bg_img").css({"height":height+"px"});
				
				$("#phone").click(function(){
					$(".nav").css("bottom","10%");
				}).blur(function(){
					$(".nav").css("bottom","60px");
				});
				
				$("#code").click(function(){
					$(".nav").css("bottom","10%");
				}).blur(function(){
					$(".nav").css("bottom","60px");
				});
				
			});
			
			function smsOverTime(t){
				var howlong=t;
				
				howlong--;
				$("#getCode").html(howlong);
				
				var timeID=setTimeout("smsOverTime("+howlong+")",1000);
				if(howlong<=0){
					clearTimeout(timeID);
					$("#getCode").html("获取验证码");
					$("#getCode").attr("disable",false);
				}
				
			}
			
			function is_weixin(){
				var ua = navigator.userAgent.toLowerCase();
				if(ua.match(/MicroMessenger/i)=="micromessenger") {
					return true;
				} else {
					return false;
				}
			}
			
			function is_qq(){
				var ua = navigator.userAgent.toLowerCase();
				if(ua.match(/MQQBrowser/i)=="mqqbrowser") {
					return true;
				} else {
					return false;
				}
			}
			
		    var browser = {
                versions: function() {
                    var u = navigator.userAgent, app = navigator.appVersion;
                    return {//移动终端浏览器版本信息 
                        trident: u.indexOf('Trident') > -1, //IE内核
                        presto: u.indexOf('Presto') > -1, //opera内核
                        webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                        gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
                        mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/), //是否为移动终端
                        ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                        android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
                        iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器
                        iPad: u.indexOf('iPad') > -1, //是否iPad
                        webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
                    };
                }(),
                language: (navigator.browserLanguage || navigator.language).toLowerCase()
            }
		    
			
			function zdxz(androidUrl,iosUrl){
				if(is_weixin()){
					window.location="${ctx}/driver/api/rest/v3/appXiazai";
			 	}
			 	else{
			 		if (browser.versions.ios || browser.versions.iPhone || browser.versions.iPad) {
			  			
			  			$("#weixin_qq").hide();
	  					$("#getApp").hide();
	  					$("#weixin_download").show();
	  					
	  					if (androidUrl && androidUrl != "") {
	  						$("#and_down_div").show();
	  						$("#and_down_div").click(function () {
	  							$.scojs_message("操作成功,准备开始下载客户端APP", $.scojs_message.TYPE_OK);
	  							window.location = androidUrl;
	  						})
	  					}
	  					
	  					if (iosUrl && iosUrl != "") {
	  						$("#ios_down_div").show();
	  						$("#ios_down_div").click(function () {
	  							$.scojs_message("操作成功,准备开始下载客户端APP", $.scojs_message.TYPE_OK);
	  							window.location = iosUrl
	  						})
	  					}
	  					
					}
					else if (browser.versions.android) {
					
						$("#weixin_qq").hide();
	  					$("#getApp").hide();
	  					$("#weixin_download").show();
	  					
	  					if (androidUrl && androidUrl != "") {
	  						$("#and_down_div").show();
	  						$("#and_down_div").click(function () {
	  							$.scojs_message("操作成功,准备开始下载客户端APP", $.scojs_message.TYPE_OK);
	  							window.location = androidUrl;
	  						})
	  					}
	  					
	  					if (iosUrl && iosUrl != "") {
	  						$("#ios_down_div").show();
	  						$("#ios_down_div").click(function () {
	  							$.scojs_message("操作成功,准备开始下载客户端APP", $.scojs_message.TYPE_OK);
	  							window.location = iosUrl
	  						})
	  					}
					}
			 	}
			}
			
	    </script>
</html>